/***************************************************************************
 $ @Description: 
 $ @Author: NavyPeng
 $ @Date: 2024-04-09 11:39:22
 $ @LastEditTime: 2024-04-19 15:10:17
 $ @LastEditors: NavyPeng
 ***************************************************************************/
#include "Ctrl.h"

#if BuilderPattern_

#include<list>

class Product 
{
public:
	list<string>* parts = new list<string>();
	void Add(string part) {
		parts->push_back(part);
	}
	void Show() {
		printf("-------产品创建-------\r\n");
		for(auto part = parts->begin(); part != parts->end(); part++)
		{
			cout << *part << endl;
		}
	}
};

class Builder 
{
public:
	virtual void BuildPartA() = 0;
	virtual void BuildPartB() = 0;
	virtual Product* GetResult() = 0;
};

class ConcreteBuilder1 : public Builder
{
private:
	Product* product = new Product();
public:
	void BuildPartA() override
	{
		product->Add("部件A");
	}
	void BuildPartB() override
	{
		product->Add("部件B");
	}
	Product* GetResult() override
	{
		return product;
	}
};

class ConcreteBuilder2 : public Builder
{
private:
	Product* product = new Product();
public:
	void BuildPartA() override
	{
		product->Add("部件X");
	}
	void BuildPartB() override
	{
		product->Add("部件Y");
	}
	Product* GetResult() override
	{
		return product;
	}
};

class Director
{
public:
	void Construct(Builder* builder) {
		builder->BuildPartA();
		builder->BuildPartB();
	}
};

int main() {
	Director* director = new Director();
	Builder* b1 = new ConcreteBuilder1();
	Builder* b2 = new ConcreteBuilder2();

	director->Construct(b1);
	Product* p1 = b1->GetResult();
	p1->Show();

	director->Construct(b2);
	Product* p2 = b2->GetResult();
	p2->Show();

}





#endif 